<%= if @plan.id == :pro do %>
    <div class="bg-yellow-50 border-t-4 border-yellow-400 p-4">
        <div class="flex">
            <div class="flex-shrink-0">
                <Icon.exclamation_triangle kind="mini" class="h-5 w-5 text-yellow-400" />
            </div>
            <div class="ml-3">
                <h3 class="my-0 text-sm font-medium text-yellow-800">You are using the legacy Pro plan.</h3>
                <div class="mt-2 text-sm text-yellow-700">
                    Please <a href={Routes.organization_billing_path(@conn, :index, @organization, source: "legacy-alert")} class="underline">migrate to the new plans</a> as mentionned in the email.
                </div>
            </div>
        </div>
    </div>
<% end %>

<%= if @projects == [] do %>
    <%= render "_project_list_empty.html", conn: @conn, organization: @organization %>
<% else %>
    <%= render "_project_list.html", conn: @conn, projects: @projects %>
<% end %>

<% user = @conn.assigns.current_user %>
<script>
    window.fetch && window.location.hostname !== 'localhost' && fetch(`https://cockpit.azimutt.app/api/events`, {
    // fetch(`http://localhost:3001/api/events`, {
        method: 'POST',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            id: '<%= Ecto.UUID.generate() %>',
            instance: '<%= Azimutt.config(:host) %>',
            environment: '<%= Azimutt.config(:environment) %>',
            name: 'organization_loaded',
            details: {host: window.location.host},
            entities: [{
                id: '<%= user.id %>',
                kind: 'users',
                name: '<%= user.name %>',
                email: '<%= user.email %>',
                avatar: '<%= user.avatar %>',
                github: '<%= user.github_username %>',
                twitter: '<%= user.twitter_username %>',
                data: JSON.parse('<%= raw if(user.data, do: user.data |> Map.from_struct() |> Jason.encode!(), else: "{}") %>'),
                is_admin: '<%= if(user.is_admin, do: "true", else: "null") %>' === 'true',
                created_at: '<%= user.created_at %>'
            }, {
                id: '<%= @organization.id %>',
                kind: 'organizations',
                name: '<%= @organization.name %>',
                logo: '<%= @organization.logo %>',
                github: '<%= @organization.github_username %>',
                twitter: '<%= @organization.twitter_username %>',
                plan: '<%= @plan.id %>',
                members: parseInt('<%= length(@organization.members) %>'),
                projects: parseInt('<%= length(@projects) %>'),
                data: JSON.parse('<%= raw if(@organization.data, do: @organization.data |> Map.from_struct() |> Jason.encode!(), else: "{}") %>'),
                is_personal: '<%= if(@organization.is_personal, do: "true", else: "null") %>' === 'true',
                created_at: '<%= @organization.created_at %>'
            }],
            createdAt: '<%= DateTime.utc_now() %>'
        })
    })
</script>
